package preprocessing;

import datastr.*;

import java.util.*;

public class GetGHash {
	
	Minutia[] list;
	Fingerprint f;
	
	public GetGHash(Fingerprint f,HashMap<Coordinate,ArrayList<Fingerprint>> hash)
	{
		this.list = f.list;
		this.f = f;
		populateHash(hash);
	}
	
	public GetGHash(Fingerprint f)
	{
		this.list = f.list;
		this.f = f;
	}
	
	public void populateHash(HashMap<Coordinate,ArrayList<Fingerprint>> hash)
	{
		int l = list.length;
		int i,j,k;
		for(i=0;i<l;i++)
		{
			for(j=0;j<l;j++)
			{
				if(i!=j)
				{
					Basis b = new Basis(list[i].x,list[i].y,list[j].x,list[j].y);
					TransformedCoord tc;
					tc = transformOthers(b,hash);
					f.tclist.add(tc);
				}
			}
		}
	}
	
	TransformedCoord transformOthers(Basis b,HashMap<Coordinate,ArrayList<Fingerprint>> hash)
	{
		TransformedCoord tc = new TransformedCoord(b);
		//now we need to populate this tc.list with the transformed co-ordinates
		//
		for(int i=0;i<list.length;i++)
		{
			double xx=0,yy=0;
			//transform this list[i] co-ordinate
			//now add to hashmap
			Coordinate c = new Coordinate(xx,yy);
			if(hash.containsKey(c))
			{
				ArrayList<Fingerprint> arr = hash.get(c);
				arr.add(f);
				hash.put(c, arr);
			}
			else
			{
				ArrayList<Fingerprint> arr = new ArrayList<Fingerprint>();
				arr.add(f);
				hash.put(c, arr);
			}
		}
		//
		//assuming we have transformed all co-ordinates and hence have populated the tc.list
		//tc is now the transformed co-ordinates
		return tc;
	}

}
